<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Controllers\main\MainController as main;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class PayController extends Controller
{
   public function getIndex(){  
    //获取数据表的内容
    $data = DB::table('address')->get(); 
    $goods = '23:1:9,26:2:17';
    // 在数据库中进行查询数据
    // $goods_car = DB::table('goods_config')
    // -> join('goods','goods.id','=','goods_config.goods_id')
    // -> join('goods_config_list','goods_config_list.id','=','goods_config.goods_config_id')
    // -> join('goods_datalist_pic','goods_datalist_pic.id','=','goods_config.goods_datalist_pic')
    // -> whereIn('goods_config.id',9)
    // -> select('goods_datalist_pic.goods_datalist_pic1','goods_config.id','goods_config.goods_id','goods_model','goods.goods_sort','goods_art','goods_stick','goods.goods_title','goods_boutique','goods_status','goods_price','goods_config_list.goods_config_cpu_brand','goods_config_list.goods_config_cpu_core','goods_config_list.goods_config_cpu_clock','goods_config_list.goods_config_cpu_type','goods_config_list.goods_config_cpu_ddr','goods_config_list.goods_config_cpu_series','goods_config_list.goods_config_disk_brand','goods_config_list.goods_config_disk_kind','goods_config_list.goods_config_disk_size','goods_config_list.goods_config_gpu_brand','goods_config_list.goods_config_gpu_type','goods_config_list.goods_config_gpu_ddr','goods_config_list.goods_config_gpu_size','goods_config_list.goods_config_mainborad_brand','goods_config_list.goods_config_mainborad_type','goods_config_list.goods_config_ram_brand','goods_config_list.goods_config_ram_ddr','goods_config_list.goods_config_ram_size')
    // -> whereIn('goods.id',$goods_id)
    // -> get();

    $explode = explode(',',$goods);  
    foreach($explode as $key=>$value){
      $index = strpos($value,':');
      $arr[] = substr($value,$index+3);
    } 

    $datas = DB::table('goods_config')
    -> join('goods','goods.id','=','goods_config.goods_id')
    -> join('goods_config_list','goods_config_list.id','=','goods_config.goods_config_id')
    -> join('goods_datalist_pic','goods_datalist_pic.id','=','goods_config.goods_datalist_pic')
    -> whereIn('goods_config.id',$arr)
    ->get();
    
  foreach($explode as $keys=>$values){
          $index1 = strpos($values,':');
          $index2 = strrpos($values,':');
          $a = substr($values,0,$index1);
          $arr1[$a]['count'] = substr($values,$index1+1,$index2-3);
          }

  foreach($datas as $k => &$v){
          foreach($arr1 as $k1=>$v1){
            if($k1 == $v['goods_id']){
         $v['count'] = $v1['count'];
          }
        }      
      }
     
      
    // $datas = main::getDatalist($explode[$dat]);
    //跳转列表页面
    return view('/home/pay/index',['data'=> $data,'datas'=> $datas]);
   }


 public function getEdit(Request $request){ 
    //获取id
    $id = $request -> only('id');  
    //获取选中的id信息
    $editdata = DB::table('address')->where('id','=',$id)->first();
    return $editdata;
    //跳转到编辑页
    // return redirect('home/shopaddr/index1',['editdata'g=> $editdata]);
    }
   
    public function getUpdate(Request $request){
       // 获取用户提交信息,并去除掉_token
       $arrs = $request -> except(['_token','provinces','countrys','towns']);
        $as = $request -> only(['provinces','countrys','towns']);
        $as1 = $request -> only(['provinces']);
        $as2 = $request -> only(['countrys']);
        $as3 = $request -> only(['towns']);
        foreach($as1 as $v1){
           $arrs['province'] = $v1;
        }
        foreach($as2 as $v2){
           $arrs['country'] = $v2;
        }
         foreach($as3 as $v3){
           $arrs['town'] = $v3;
        }
        $arrays = implode($as); 
        $arrs['address1'] = $arrays;      
        $res = DB::table('address') -> where('id',$request -> only('uid')) -> update($arrs);
        //跳转到主页
       return redirect('home/pay/index');
   }
    /**
    * delete()进入路由前台删除
    *
    * @return 返回前台首页视图
    */
    public function getDelete(Request $request){
     //获取删除的ID
     $id = $request -> only('id');
     //删除表内的ID
     DB::table('address')->where('id','=',$id)->delete();
    //跳转到主页
     return redirect('home/pay/index');
   }
}
